<template>
    <div class="cash-total-box" v-loading="loading">
        <div class="input-box">
            <el-date-picker
                @change="getList(1)"
                v-model="date"
                style="margin-left:10px;"
                type="daterange"
                value-format="yyyy-MM-dd"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期">
            </el-date-picker>
            <!-- <el-button type="primary" class="btn" @click="getList(1)">搜索</el-button> -->
        </div>

        <div class="table-box">
            <el-table
                :data="list"
                border
                style="width: 100%">
                <el-table-column
                    label="日期">
                    <template slot-scope="scope">
                        <div>{{initTime(scope.row.date)}}</div>
                    </template>
                </el-table-column>
                <el-table-column
                    label="提现人数">
                    <template slot-scope="scope">
                        <span>{{scope.row.userCount || '-'}}</span>
                    </template>
                </el-table-column>
                <el-table-column
                    label="提现次数">
                    <template slot-scope="scope">
                        <span>{{scope.row.count || '-'}}</span>
                    </template>
                </el-table-column>
                <el-table-column
                    label="提现金额">
                    <template slot-scope="scope">
                        <span>{{scope.row.money || '-'}}</span>
                    </template>
                </el-table-column>
            </el-table>
        </div>

        <div class="tools">
            <el-pagination
                @size-change="sizeChange"
                @current-change="pageChange"
                :current-page="pageNum"
                :page-sizes="_pageSizes"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total">
            </el-pagination>
        </div>
    </div>
</template>

<script>
import { formatDate } from '@/utils/utils'
export default {
    data  () {
        return {
            list: [],
            loading: false,
            pageNum: 1,
            pageSize: this._pageSize,
            total: 0,
            date: [] // 选中的日期
        }
    },

    created () {
        this.getList(1)
    },

    methods: {
        async getList (num) {
            if (this.loading) return
            this.loading = true
            this.pageNum = num
            let params = {
                pageNum: this.pageNum,
                pageSize: this.pageSize
            }
            if (this.date && this.date.length) {
                params.fromDate = this.date[0]
                params.toDate = this.date[1]
            }
            let res = await this.$http.post('/withdraw/total', params)
            if (res.code === '0') {
                this.list = res.data
                this.total = res.count
            } else {
                this.$message({
                    type: 'error',
                    message: res.desc
                })
            }
            this.loading = false
        },

        initTime (time) {
            if (time) {
                return formatDate(new Date(time), 'YYYY-MM-DD')
            } else {
                return '-'
            }
        },

        // 页容切换
        sizeChange (val) {
            this.pageSize = val
            this.getList(1)
        },

        // 页码切换
        pageChange (val) {
            this.pageNum = val
            this.getList(this.pageNum)
        }
    }
}
</script>

<style lang="scss" scoped>
    .cash-total-box {
        .input-box {
            .btn {
                margin-left: 10px;
            }
        }
        .table-box {
            margin: 20px 0;
        }
        .tools {
            padding-right: 20px;
            display: flex;
            justify-content: flex-end;
        }
    }
</style>
